package com.walsai.pcsys.core.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;


@Entity
public class Contest extends BaseObject implements Serializable{
	private static final long serialVersionUID = 8273472412L;
	
	private long id;
	private String name;
	private Date beginDate;
	private Date endDate;
	private List<Problem> problems = new ArrayList<Problem>();
	private List<User> participants = new ArrayList<User>();
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public long getId() {
		return id;
	}
	
	@Column
	public String getName() {
		return name;
	}
	
	@Column(name="begin_date", nullable=false)
	public Date getBeginDate() {
		return beginDate;
	}
	
	@Column(name="end_date", nullable=false)
	public Date getEndDate() {
		return endDate;
	}

	@OneToMany(mappedBy="contest")
	public List<Problem> getProblems() {
		return problems;
	}
	
	@ManyToMany(targetEntity=User.class)
	public List<User> getParticipants() {
		return participants;
	}
	

	public void setId(long id) {
		this.id = id;
	}
	public void setName(String name){
		this.name = name;
	}
	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
	public void setProblems(List<Problem> problems) {
		this.problems = problems;
	}
	public void setParticipants(List<User> participants) {
		this.participants = participants;
	}

	@Override
	public boolean equals(Object o) {
        boolean result = false;
        if (o != null && getClass() == o.getClass()) {
            final Contest p = (Contest) o;
            if (this.id == p.id) {
                result = true;
            }
        }
        return result;
	}

	@Override
	public int hashCode() {
		return  (int)(this.id^(this.id>>>32));
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return null;
	}
}
